using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InvestmentIntelligence.DbModel.Models.Mapping
{
    public class OriginalPositionMap : EntityTypeConfiguration<OriginalPosition>
    {
        public OriginalPositionMap()
        {
            // Primary Key
            this.HasKey(t => new { t.FundBookEntityId, t.SecurityId, t.Date });
            // Properties
            this.Property(t => t.SecurityId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.FundBookEntityId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("OriginalPosition", "TradingData");
            this.Property(t => t.FundBookEntityId).HasColumnName("FundBookEntityId");
            this.Property(x => x.FundBookEntityId).HasColumnOrder(0);
            this.Property(t => t.SecurityId).HasColumnName("SecurityId");
            this.Property(x => x.SecurityId).HasColumnOrder(1);
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.Date).HasColumnOrder(2);
            this.Property(t => t.CloseQuantity).HasColumnName("CloseQuantity");
            this.Property(t => t.PositionPL).HasColumnName("PositionPL");
            this.Property(t => t.TradePL).HasColumnName("TradePL");
            this.Property(t => t.CloseExposure).HasColumnName("CloseExposure");

            // Relationships
            this.HasRequired(t => t.FundBookEntity);
            this.HasRequired(t => t.Security);
            this.HasOptional(c => c.OriginalPositionValidationData).WithRequired();


        }
    }
}
